package com.example.doctor.config;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;

import javax.annotation.Resource;

import com.zaxxer.hikari.HikariDataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;

/**
 * 基本配置
 *
 * @Author wxy
 * @Date 2020/9/22 11:07
 * @Version 1.0
 */
@Configuration
@EnableJpaRepositories(value = {"com.example.doctor.jpa"}, transactionManagerRef = "jpaTransactionManager")
public class BasicConfig {
    @Resource
    private HikariDataSource dataSource;

    
    /**
     * JPA事务管理器
     */
    @Bean("jpaTransactionManager")
    public JpaTransactionManager jpaTransactionManager() {
        JpaTransactionManager jpa = new JpaTransactionManager();
        jpa.setDataSource(dataSource);
        jpa.setRollbackOnCommitFailure(true);
        return jpa;
    }

    /**
     * 指定feign-client encoder
     */
    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder();
    }
}
